package pATT.DataSetsGenerator.dataSetsGenerator.generator.implement;


import java.util.Vector;

import pATT.DataSetsGenerator.dataSetsGenerator.core.implement.Relation;
import pATT.DataSetsGenerator.dataSetsGenerator.data.implement.IData;
import pATT.DataSetsGenerator.dataSetsGenerator.data.implement.RandomExponentialData;

public class RandomExponentialGenerator extends Generator {
	
	public RandomExponentialGenerator(Relation relat) {
		super(relat);
	}
	
	@SuppressWarnings("unchecked")
	public Vector generate(IData data){
		if(((RandomExponentialData)data).getMedia() != -1){
		Vector instances = ((RandomExponentialData)data).getAttribute().getValues(); 
		int cantRules = getRelation().getExamples();
		Vector result= new Vector();
		int i = 0; 
		double doub;
		RandomExponentialData exp = (RandomExponentialData)data;
		double media = exp.getMedia();
		while(i < cantRules) {
			doub = exponential(media);// 0<media<cantidad de instancias, doub me da el valor dentro de las instancias 
			if(doub < instances.size()){
				result.addElement(instances.elementAt((int)doub));
				i++;
			}
		}
		return result;
		}
		else{
			System.out.println("------------->FUe al random comun");
			return (new RandomGenerator(relation)).generate(data);
		}
	}
	
	public double exponential(double media)
	/* =========================================================
	 * Returns an exponentially distributed positive real number. 
	 * NOTE: use m > 0.0
	 * =========================================================
	 */
	{
		return (-media * Math.log(1.0 - Math.random()));
	}
}
